package com.xuwenjin.basic_juc;

import java.util.concurrent.*;


//步骤
//1创建执行服务, 2 提交执行  3 获取结果  4 关闭服务

// 好处
//1. 有返回值
//2 因为run()方法是Runnable接口里面的方法,
// 而Runnable接口在定义run()方法的时候没有抛出任何异常,所以子类在重写run()方法的时候要小于或等于父类(Runnable)的run()方法的异常,所以父类没有抛出异常,子类不能抛出异常
public class TestCallable implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(111);
        return "hahah";

    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        Future<String> submit = executorService.submit(new TestCallable());
        try {
            String s = submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executorService.shutdown();

//        Executors.defaultThreadFactory()
//        new ThreadPoolExecutor()
    }


}
